feat(worktrees): manage lifecycle on orchestrator v2 - #5589
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
There was a problem hiding this comment.
Reviewed the new worktree services against the Effect service conventions. Four convention issues found: two standalone *Shape service interfaces, a redundant singleton operation discriminator plus free-form message on the new worktree error classes, and a hidden optional service dependency in ProviderTurnStartService.
Posted via Macroscope — Effect Service Conventions
There was a problem hiding this comment.
Effect service conventions review of the worktree management services. Prior findings on WorktreeLifecycle/WorktreeRevivalService shape interfaces, the unstructured worktree error payloads, and the Effect.serviceOption acquisition of WorktreeRevivalService all look addressed. A few smaller convention issues remain.
Posted via Macroscope — Effect Service Conventions
25de21d to
0af2a6e
Compare
0f4d58b to
8f7ca24
Compare
22bd872 to
a27c1cc
Compare
61184a3 to
d56b638
Compare
There was a problem hiding this comment.
One finding: raw git stderr is copied into a new error attribute. Everything flagged in earlier runs (service-shape interfaces, make/layer naming, the single-use mutationError helper, the parseWorktreeBranchPaths shim, structural stages on the new worktree errors, and the hidden WorktreeRevivalService requirement) is resolved in this revision.
Posted via Macroscope — Effect Service Conventions
There was a problem hiding this comment.
Reviewed the Effect service conventions in this update. Previously flagged items (inline service interfaces, plain make/layer names, structural error stages with derived messages, required WorktreeRevivalService acquisition in ProviderTurnStartService, shared worktree porcelain parser, bounded git worktree list error context) all look resolved. One remaining error-modeling nit below.
Posted via Macroscope — Effect Service Conventions
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR adds server-owned worktree inventory, automatic cleanup, revival, new RPCs, and provider-session lifecycle behavior across the production server and client. It also introduces a default 14-day automatic-pruning policy, so the breadth, side effects, and changed product defaults warrant human review. Not approved because:
Review your spending limits in Billing settings, or comment |
There was a problem hiding this comment.
One finding on the new GitVcsDriver.listWorkspaces truncation error: its context fields are hardcoded/fabricated rather than derived from the actual command and output.
Posted via Macroscope — Effect Service Conventions
a186d64 to
5b1a115
Compare
- Re-route steering that races completion into idempotent follow-up dispatches - Preserve scheduled-task attribution and provider ownership history across clients
Port main's pull-request discovery, active thread ordering, async question dismissal, settlement fixes, provider-session import, attachment context, and provider correctness changes into orchestration v2. Keep the branch's intentional composer and subagent behavior while adopting main's web and mobile fixes. Prevent headless setup terminals from hanging on the color probe, and move the v2 migration block to 050-061 after main claimed 048-049.
Restore the failed-before-start timer guard, align two server fixtures with the reconciled behavior, and remove dead files, exports, and dependencies surfaced by Knip. Drop the temporary branch push trigger now that the PR is mergeable, so each update runs the pull-request workflow once.
Keep main's batch machine-update banner and update action while preserving the v2 runtime-based environment lock used by draft load balancing.
Adopt TypeScript 7 and Effect rc.112 across orchestration v2, including the TaggedError API migration and updated Effect-aware tests. Restore main's composer-aware scroll-to-end clearance while retaining selected-model settings sync, preview recording transfer, image galleries, desktop context menus, and layout hit targets. Regenerate the lockfile on the upgraded dependency baseline.
Advertise bounded socket snapshots and authoritative dispatch validation, omit raw command output and inline file bodies at the wire boundary, and preserve compact status metadata across web and mobile. Add transport-budget coverage for snapshots, resume, commands, legacy import, and projection maintenance.
Restore pinned-thread shelf classification, server-owned unread state, hidden-subagent-safe project ordering, guarded jump hints, draft upload cleanup, and active-provider archive guards across the current and legacy sidebars. Bring the surrounding current-main sidebar work forward as well: canonical project favicons, stable row layout, thread file drops, account-aware mobile provider badges, and deferred desktop keyring loading.
Keep collapsed model controls in a strip, contain transition overflow, and preserve timeline spacing. Render approval requests as regular grouped worklog entries. Implemented with GPT-6-Astra via Codex.
Adapt question attachments and Android push verification to V2 requests and shell events. Preserve composer transitions and compact worklogs while integrating upstream loading, navigation, and mobile changes. Release consumed application replay pages without retaining earlier batches.
8187b17 to
ada72ce
Compare
Rebased onto the current t3code/codex-turn-mapping base. The base's interim inline worktree repair in ProviderTurnStartService is replaced by the revival service this change introduces. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
bdc613b to
8feb1e7
Compare
|
Macroscope skipped reviewing this pull request. Per-review cost limit exceeded (workspace setting). This review would cost an estimated $8.41, which exceeds your per-review limit of $8.00. The top 3 files driving up this estimate:
Tip To get this pull request reviewed, you can:
|
Revival only creates a missing directory. An existing worktree is left as is, whatever ref it has checked out and wherever it lives, so a detached HEAD, a switched branch, or a checkout outside the managed root no longer fails every turn. A failed revival logs and lets the provider report the missing directory instead of stranding the run in starting. Only per-thread provider sessions restart after a revival; a session shared across threads passes cwd per native thread and closing it would fail sibling turns. Turn starts no longer take the mutation permit when the directory exists, and the reaper holds it per worktree instead of per batch. Also: a worktree with no linked thread is not orphaned, a project whose directory is gone is skipped instead of failing the inventory, deletion cleanup backoff is capped, unused exports are dropped, and the settings search test queries the worktrees entry by title. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
e03e376 to
e39429e
Compare
Important
Stacked pull request. This targets
t3code/codex-turn-mappingfrom #2829. After #2829 merges, rebase this branch and retarget the PR tomain.Problem
Thread worktrees accumulate without a server-owned way to inspect or clean them. The previous cleanup prompt only worked in the desktop client, and a removed worktree could strand the next provider turn.
Solution
git statusper worktree, concurrently with the ahead-of-default count, and fetch the per-repository listing, branch sync, and default ref together. On a 2-vCPU environment with 8 worktrees the inventory went from 5.0 s to 0.6 s. Mounting the section no longer issues a duplicate read.The refresh also removes the unused public revive RPC, fixes provider-start supersession after a mandatory session reopen, parses
git worktree list --porcelain -zeverywhere (main already requires-zinlistRefs), keeps the reaper behind the activation boundary, lets interrupts stop sweeps and status reads, and skips projects outside a Git repository instead of failing the inventory.Safety
Screenshots
Verification
Initial implementation and the refresh were produced with GPT-5.6 Sol via Codex in T3 Code. The one-line settings layout, detached-HEAD handling, inventory speed-up, and review follow-ups were done by Claude Fable 5 via Claude Code in T3 Code.
The rebase onto the current orchestrator v2 base, which replaces the base's interim inline worktree repair with the revival service, was done by Claude Fable 5.1 via Claude Code in T3 Code, as were the pre-review fixes that leave existing worktrees alone at turn start and take the mutation permit per worktree.
Note
Add server-side worktree lifecycle management to orchestrator v2
WorktreeService,WorktreeRevivalService,WorktreeLifecycle,WorktreeReaper, andWorktreeDeletionCleanupservices that handle listing, pruning, reviving, and reaping worktrees on the serverProviderTurnStartServicenow revives the thread's worktree before starting a provider turn, serializes session starts perProviderSessionId, and closes/reopens the provider session when the worktree was revived or its generation/path changedvcs.listWorktrees,vcs.subscribeWorktreeInventory,vcs.pruneWorktrees) with auth scopes, and aworktreeManagementcapability flag so clients gate features on server supportautoPruneAfterDaysdefault 14,deleteOrphanedImmediatelydefault false), and pruning;useThreadActionsskips legacy client-side orphan cleanup when the capability is presentGitWorkflowServicemethods (preparePullRequestThread,createWorktree,removeWorktree) now run under aWorktreeLifecyclemutation permit and signal inventory changesProviderTurnStartServiceno longer emitsprovider-session.updatedandprovider-thread.updatedevents during the initial running transition; consumers relying on those events in that phase will need to userun.updated,run-attempt.updated, ornode.updatedinsteadMacroscope summarized bdc613b.
Note
High Risk
Touches provider turn startup, shared session close/reopen, and automatic worktree deletion; race-sensitive paths are tested but mistakes could strand runs or remove worktrees incorrectly.
Overview
Adds server-owned Git worktree lifecycle for orchestration v2: inventory from
git worktree list, safe pruning rules, automatic retention/orphan cleanup, and revival of missing thread worktrees before provider turns run.Git & workflow: New
listWorkspaces/ shared porcelain parsing (GitWorktree.ts), with output-size limits.GitWorkflowServiceroutes create/remove/prepare-PR-thread work throughWorktreeLifecycle(serialized mutations + inventory revision stream).Orchestration:
ProviderTurnStartServicecallsWorktreeRevivalService.reviveForThread, then serializes startup perProviderSessionIdviaKeyedSerialExecutor. If a worktree was revived or its generation/path changed, it closes and reopens the shared provider session so cwd stays correct, with careful handling when runs are superseded mid-restart.Background jobs:
WorktreeDeletionCleanupreacts tothread.deletedevents;WorktreeReaperperiodically prunes inactive safe worktrees per settings. Both delegate toWorktreeServicefor last-moment safety checks.Product surface: Enables
worktreeManagementserver capability and RPC auth forvcsListWorktrees,subscribeWorktreeInventory, andvcsPruneWorktrees. Layers wired inserver.ts/ startup after the effect worker starts.Reviewed by Cursor Bugbot for commit bdc613b. Bugbot is set up for automated code reviews on this repo. Configure here.